package com.lxz.bookmanager.service.impl;

import com.lxz.bookmanager.entity.Book;
import com.lxz.bookmanager.mapper.BookMapper;
import com.lxz.bookmanager.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

@Service
public class BookServiceImpl implements BookService {

    @Autowired
    private BookMapper bookMapper;

    @Override
    public List<Book> getAllBook() {
        return bookMapper.getAllBook();
    }

    @Override
    public Book getBookById(String id) {
        Map<String, Object> map = new HashMap<>();
        map.put("book_id",id);
        List<Book> books = bookMapper.selectByMap(map);
        return books.get(0);
    }

    @Override
    public int selectBookCount(String id) {
        return bookMapper.selectBookCount(id);
    }

    @Override
    public void updateBook(Book book) {
        bookMapper.updateBook(book);
    }

    @Override
    public void deleteBook(long id) {
        bookMapper.deleteBook(id);
    }

    @Override
    public void addBook(Book book) {
        book.setBookId(UUID.randomUUID().timestamp());
        bookMapper.insert(book);
    }

    @Override
    public List<Book> searchBook(String keyword) {
        return bookMapper.searchBook(keyword);
    }
}
